/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package firma;

import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author tomasz
 */
@Controller
public class FirmaView {
    
    
    private dao.Firma firma;
    
    @Autowired
    public void setFirma(dao.Firma firma){
        this.firma = firma;
    }
    
    
    @RequestMapping("/view/firma.htm/{id}")
    public String taskList(ModelMap model, @PathVariable Integer id)
    {
         model.Firma firma = this.firma.findFirmaId(id);
         model.addAttribute("firma", firma);
         return "/firma/firma_view";
    }
    
    
    
    
    @RequestMapping(value = "/create/data/firma.htm", method = RequestMethod.POST)
    public @ResponseBody model.Firma getFirmaJSON(HttpServletResponse response, HttpServletRequest request) {
 
                int id = Integer.parseInt( request.getParameter("id_f") );
                
                /**
                 * from Firma f left join f.accounts  Account where Account.idAccount is null
                 */
                
                model.Firma firma = this.firma.findFirmaId(id);
                firma.setAccounts(null);
                

		return firma;
        
	}
    
}
